layui.use(['form', 'jquery', 'layer'], function() {
	var form = layui.form;
	var $ = layui.$;
	var layer = layui.layer;
	// 获取指纹
	$.getScript('https://lib.baomitu.com/fingerprintjs/0.5.3/fingerprint.min.js');
	setTimeout(()=>{
		fingerprint = new Fingerprint().get()
		$('#fingerprint').val(fingerprint.toString(2))
		$('.csdn-div').html(fingerprint.toString(2))
	},100)
	$('.forget').on('click',()=>{
		layer.confirm(fingerprint.toString(2), { title:'当前浏览器指纹',btn:[]}, function(index){
		  //do something
		  
		  layer.close(index);
		});
	})
	// 验证码
	$('.login-verify').on('click', function() {
		var url = $(this).attr('src');
		var new_url = url.split('?');
		$(this).attr('src', new_url[0] + '?rand=' + Math.random());
	})
	// 倒计时
	var time_num = 120,
		h;
	var de_time = function(){
		h = setInterval(function(){
			time_num--;
			if(time_num<=0){
				$('.get-phone-code').html('短信码失效')
				$('.login_btn').text('获取验证码')
				$('input[name="verify"]').val('')
				$('.phone-code').hide()
				clearInterval(h)
			} else {
				$('.get-phone-code').html(time_num + 's后短信码失效')
			}
		},1000)
	}
	form.on('submit(login_btn)', function(data) {
		var url = data.form.action;
		var field = data.field;
		if($('.login_btn').text() == '登录账号'){
			if(field.phone_code.length != 6){
				layer.msg('请输入6位数短信验证码', {
					icon: 2,
					anim: 6
				});
				return false;
			}
		}
		$.ajax({
			type: "post",
			url: url,
			async: true,
			data: field,
			dataType: 'json',
			success: function(data) {
				if(data.code == 0) {
					if(data.data != 'phone_msg'){
						$('.login-verify').trigger('click');
						$('input[name="verify"]').val('');
					} else {
						$('input[name="phone_code"]').val('');
					}
					
					layer.msg(data.msg, {
						icon: 2,
						anim: 6
					});
					return false;
				} else {
					if(data.data == 'open_tips'){
						layer.msg('获取验证码成功', {
							icon: 1,
							anim: 6
						});
						de_time()
						$('.login_btn').text('登录账号')
						$('.phone-code').show()
					} else {
						location.href = data.url;
					}
				}
			},
			error: function(xhr, type, errorThrown) {
				layer.msg('请求失败，访问地址：' + string_uri, {
					icon: 2,
					anim: 6
				});
			}
		});
		return false;
	})
})